package com.sphd.beautysalon.adapters;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.sphd.beautysalon.R;
import com.sphd.beautysalon.info.BlueToothPrinterInfo;
import com.sphd.beautysalon.interfaces.RecyclerViewOnClickListener;

import java.util.List;


/**
 * Created by Administrator on 2015/6/23.
 */
public class BluetoothPtrinterAdapter extends RecyclerView.Adapter {

    private List<BlueToothPrinterInfo> bluetoothPrinterList;
    private RecyclerViewOnClickListener recyclerViewOnClickListener;

    public void setRecyclerViewOnClickListener(RecyclerViewOnClickListener recyclerViewOnClickListener) {
        this.recyclerViewOnClickListener = recyclerViewOnClickListener;
    }

    public BluetoothPtrinterAdapter(List<BlueToothPrinterInfo> bluetoothPrinterList) {
        this.bluetoothPrinterList = bluetoothPrinterList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_bluetoothprinter_item, parent, false);
        return new BlueToothPrinterViewHold(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        ((BlueToothPrinterViewHold) holder).position = position;
        ((BlueToothPrinterViewHold) holder).printerName.setText(bluetoothPrinterList.get(position).getName()+"\n"
        +bluetoothPrinterList.get(position).getMacadd());
    }

    @Override
    public int getItemCount() {
        return bluetoothPrinterList.size();
    }

    class BlueToothPrinterViewHold extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView printerName;
        Button onlineButton;
        int position;

        public BlueToothPrinterViewHold(View itemView) {
            super(itemView);
            printerName = (TextView) itemView.findViewById(R.id.bluetooth_name);
            onlineButton = (Button) itemView.findViewById(R.id.online_button);
            onlineButton.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            recyclerViewOnClickListener.onTouch(v, position);
        }

    }
}
